package src.model.gameWorld;

import src.model.gameObject.*;
import src.driver.PlayerObjectData;
import src.model.gameObject.ability.*;

import java.util.Collection;
import java.util.Vector;

/**
 * <b>Overview</b><br>
 * <p>In order to represent a Player in the game world, we need to have
 * some sort of construct that is capable of receiving messages from
 * the controller and carrying out the player's actions.  The Plaeyr
 * class is the back end of this system, while the Current Player ensures
 * the proper messeages get routed to the correct Player.</p>
 * <br><br>
 * <b>Responsibilites</b><br>
 * <p>The Player class is responsible for representing the player in the
 * game world</p>
 * <br><br>
 * <b>Collaborators</b>
 * <ul>
 * <li>PlayerLookupTable - Subcontractor</li>
 * <li>Research - Subcontractor</li>
 * <li>PlayerObjectData - Subcontractor</li>
 * <li>PlayerMap - Subcontractor</li>
 * <li>PlayerGameObject - Client</li>
 * </ul>
 * <br><br>
 * <b>Implementor</b> - Brent<br>
 * <b>Tester</b> - Tim<br>
 * 
 * @author Brent
 *
 */
public class Player
{
	private PlayerLookupTable myLookupTable;
	private Research myResearch;
	private PlayerObjectData pod;
	private PlayerMap playerMap;
	private Vector<PlayerGameObject> myGameObjects;

	public Player(PlayerObjectData pod, ActualMap map)
	{
		this.pod = pod;
		this.playerMap = new PlayerMap(map);
		myLookupTable = new PlayerLookupTable("data/model/lookupTableStats.lts");
		myGameObjects = new Vector<PlayerGameObject>();

	}

	public void newUnit(PlayerGameObject pgo, Position p){
		//Add to my collection, and change my vision
		myGameObjects.add(pgo);
		
		View v = (View)pgo.getAbility(AbilityType.VIEW);
		
		playerMap.ExpandVision(p, (int)v.getAttribute(AbilityAttributes.MAXIMUM));
	}

	public void unitDeath(PlayerGameObject pgo, Position p){
		//Remove from my collection, and change my vision
		myGameObjects.remove(pgo);
		
		View v = (View)pgo.getAbility(AbilityType.VIEW);
		
		playerMap.ReduceVision(p, (int)v.getAttribute(AbilityAttributes.MAXIMUM));
	}

	public PlayerGameObject selectNextUnit()
	{
		return null;
	}

	public PlayerGameObject selectNextStructure()
	{
		return null;
	}

	public Collection<PlayerGameObject> getAllGameObjects()
	{
		return myGameObjects;
	}
	
	public PlayerMap getPlayerMap()
	{
		return playerMap;
	}

	public void beginTurn()
	{
		// reset all stuff
		for(PlayerGameObject pgo : myGameObjects)
			pgo.resetAbilites();
		
		Vector<PlayerGameObject> temp = new Vector<PlayerGameObject>();
		temp.add(myGameObjects.get(0));
		
		GameObjectEventHandler.swapSelectedUnits(temp);
		
		playerMap.UpdateMap();
		
		//myResearch.researchCurrentTech();
		
	}

	public void endTurn()
	{
		// do more stuff
	}

	/**
	 * Returns if a Player is Valid (i.e. still has structures)
	 * @return true if and only if the player is Valid
	 */
	public boolean isValid()
	{
		return true;
	}

	public String getName(){
		return pod.getPlayerName();
	}
	
	public PlayerLookupTable getLookupTable()
	{
		return myLookupTable;
	}

	public java.awt.Color getColor(){
		return pod.getPlayerColor();
	}

}
